package algotithm.weekendrace.leetcode231.test1;

import java.util.HashMap;

/**
 * @author zhouyanxiang
 * @Date 2021-03-2021/3/7-10:28
 * @Title 5697. 检查二进制字符串字段
 */
public class Solution {

    public static void main(String[] args) {
        String s = "10000";
        Solution solution = new Solution();
        boolean b = solution.checkOnesSegment(s);
        System.out.println(b);
    }

    public boolean checkOnesSegment(String s) {
        char[] c = s.toCharArray();
        int n = 0;
        int m = 0;
        HashMap<Character,Integer> map = new HashMap<>();
        for (int i = 0; i < c.length; i++) {
            if (c[i] == '1' && map.containsKey(c[i])) {
                if (Math.abs(i - map.get(c[i])) > 1) {
                    return false;
                }
            }
            map.put(c[i],i);
        }
        return true;
    }

}
